package com.dq.domain.address;

import com.dq.annotation.validator.Name;
import com.dq.annotation.validator.Phone;
import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.base.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

/**
 * @author liuhui
 * @date 2019/9/12 0012 14:52:56
 */
@Data
@Entity
@ApiModel("地址管理")
public class Address extends BaseEntity implements VO.ToVO {
    @ApiModelProperty(value = "用户", hidden = true)
    @ManyToOne
    protected SysUser user;

    @ApiModelProperty(value = "门店", hidden = true)
    @ManyToOne
    protected Org org;

    @ApiModelProperty("联系人姓名")
    @Name
    protected String name;

    @ApiModelProperty("国家")
    protected String country;

    @ApiModelProperty("省份")
    @NotNull
    protected String province;
    @ApiModelProperty("城市")
    @NotNull
    protected String city;
    @ApiModelProperty("区县")
    @NotNull
    protected String district;
    @ApiModelProperty("详细地址")
    @NotNull
    protected String address;
    @ApiModelProperty("联系电话")
    @Phone
    protected String contaceMobile;

    @ApiModelProperty("是否是默认地址")
    protected Boolean isDefault;

    @Data
    @ApiModel(value = "地址视图")
    public static class Vo implements VO {
        private Long id;
        @ApiModelProperty("国家")
        private String country;
        @ApiModelProperty("省份")
        private String province;
        @ApiModelProperty("联系人姓名")
        private String name;
        @ApiModelProperty("城市")
        private String city;
        @ApiModelProperty("区县")
        private String district;
        @ApiModelProperty("详细地址")
        private String address;
        @ApiModelProperty("联系电话")
        private String contaceMobile;
        @ApiModelProperty("是否是默认地址")
        private Boolean isDefault;

    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.country = this.country;
        vo.province = this.province;
        vo.city = this.city;
        vo.district = this.district;
        vo.address = this.address;
        vo.contaceMobile = this.contaceMobile;
        vo.isDefault = fmt(this.isDefault);
        vo.name = this.name;
        vo.id = this.id;
        return vo;
    }

    public String getAllAddress() {
        return fmt(this.province) + fmt(this.city) + fmt(this.country) + this.address;
    }
}
